package gsp420.game;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.lang.reflect.Method;

import javax.swing.JFrame;

// this could be used as java applet code
//<APPLET ARCHIVE="game.jar" CODE="gsp420.game.GameMain.class" WIDTH=90% HEIGHT=90%>
//</APPLET>
/**
 * 
 * @author Administrator
 * 
 */
public class GameMain extends Applet
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * mostly a debug function to show off the reflection
	 * powers of Java
	 * 
	 * @param className
	 */
	public void reflect(String className)
	{
		try
		{
			Class cls = Class.forName(className);
			Method methlist[] = cls.getDeclaredMethods();
			for (int i = 0; i < methlist.length; i++)
			{
				Method m = methlist[i];
				System.out.println("name = " + m.getName());
				System.out.println("decl class = "
						+ m.getDeclaringClass());
				Class pvec[] = m.getParameterTypes();
				for (int j = 0; j < pvec.length; j++)
					System.out.println("param #" + j + " "
							+ pvec[j]);
				Class evec[] = m.getExceptionTypes();
				for (int j = 0; j < evec.length; j++)
					System.out.println("exc #" + j + " "
							+ evec[j]);
				System.out.println("return type = "
						+ m.getReturnType());
				System.out.println("-----");
			}
		} catch (Throwable e)
		{
			System.err.println(e);
		}
	}

	public void init()
	{
		RTSGame g = RTSGame.getInstance();// new RTSGame();
		this.setLayout(new BorderLayout());
		this.add(g, BorderLayout.CENTER);
		Thread t = new Thread(g);
		t.start();

		reflect("gsp420.game.RTSGame");
	}

	public static void main(String[] args)
	{
		RTSGame g = RTSGame.getInstance();// new RTSGame();
		JFrame gameWindow = new JFrame("game");
		gameWindow.add(g);
		gameWindow.setSize(800, 600);
		gameWindow.setVisible(true);
		gameWindow
				.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Thread t = new Thread(g);
		t.start();
	}

}
